package top.mable.spring.boot.samples.autoconfiguration.formatter;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import top.mable.DefaultFormatter;
import top.mable.Formatter;
import top.mable.JsonFormatter;

/**
 * @author taffywen
 * @date 2022/5/16 23:07
 */

@Configuration
public class FormatterAutoConfiguration {

    /**
     * {@link DefaultFormatter}
     * @return
     */
    @Bean
    @ConditionalOnMissingClass (value = "com.fasterxml.jackson.databind.ObjectMapper")
    public Formatter DefaultFormatter(){

        return new DefaultFormatter();
    }

    @Bean
    @ConditionalOnClass(name = "com.fasterxml.jackson.databind.ObjectMapper")
    public Formatter jsonFormatter(){
        return new JsonFormatter();
    }
}
